package main

import (
	"github.com/kcpserver/kcptest"
	"github.com/wonderivan/logger"
	"github.com/xtaci/kcp-go"
)

type EventHandler struct {
}

func NewEventHandler() *EventHandler {
	return &EventHandler{}
}
func (handler *EventHandler) OnRead(conn *kcp.UDPSession, readBuf []byte) {
	logger.Debug("OnRead readBuf=%s", string(readBuf))
	conn.Write(readBuf)
}

func (handler *EventHandler) OnClose(conn *kcp.UDPSession) {
	logger.Debug("OnClose")
}

func main() {
	//http://vearne.cc/archives/39331
	//普通模式：ikcp_nodelay(kcp, 0, 40, 0, 0); 极速模式： ikcp_nodelay(kcp, 1, 10, 2, 1);
	logger.SetLogger("log.json")
	kcpsrv := kcptest.NewKcpServer()
	kcpsrv.Start(9000, NewEventHandler())
	select {}
}
